# Maintainer:
# Contributor: Geoffroy Carrier <geoffroy@archlinux.org>
# Contributor: Thorsten Tasch <tht@thorstentasch.de>
# Contributor: JJDaNiMoTh <jjdanimoth@gmail.com>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>

pkgname=rsnapshot
pkgver=1.4.4
pkgrel=1
pkgdesc="A remote filesystem snapshot utility"
arch=('any')
url="https://www.rsnapshot.org"
license=('GPL')
depends=('perl' 'rsync' 'openssh' 'perl-lchown')
backup=('etc/rsnapshot.conf')
source=("$pkgname-$pkgver.tar.gz::https://github.com/rsnapshot/rsnapshot/archive/$pkgver.tar.gz"
        'rsnapshot'
		'0001-added-missing-back.patch'
		"pod-fix.patch")
md5sums=('1e02d95b41bb7e01e04328d21418ea9e'
         '4cd16eaa51d58a652cffde945985e91c'
         'a7075d9366eda5e699be86f7ffe8246e'
         '0d889cbef6fddf8401611bc16ed63c5c')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	patch -p1 -i "$srcdir/0001-added-missing-back.patch"
	patch -p1 -i "$srcdir/pod-fix.patch"

	# SSH testing requires a local SSH daemon with a specific user and won't
	# work reliably on different build hosts.
	rm t/ssh_args/ssh_args.t.in
}

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	./autogen.sh
	./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man
	sed -i 's:/usr/bin/pod2man:/usr/bin/core_perl/pod2man:' Makefile
	make
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make test
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	make DESTDIR=${pkgdir} install
	install -Dm755 utils/rsnapreport.pl "$pkgdir/usr/bin/rsnapreport.pl"
	mv "${pkgdir}/etc/rsnapshot.conf.default" "${pkgdir}/etc/rsnapshot.conf"
	install -Dm644 "${srcdir}/rsnapshot" "${pkgdir}/etc/logrotate.d/rsnapshot"
}
